home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / cug172 / eclosu.c < prev    next >
C/C++ Source or Header  |  1986-02-05  |  2KB  |  65 lines

  1. /*
  2.   HEADER: CUG     nnn.nn;
  3.   TITLE:     LEX - A Lexical Analyser Generator
  4.   VERSION:     1.0 for IBM-PC
  5.   DATE:      Jan 30, 1985
  6.   DESCRIPTION:     A Lexical Analyser Generator. From UNIX
  7.   KEYWORDS:     Lexical Analyser Generator YACC C PREP
  8.   SYSTEM:     IBM-PC and Compatiables
  9.   FILENAME:      ECLOSU.C
  10.   WARNINGS:     This program is not for the casual user. It will
  11.          be useful primarily to expert developers.
  12.   CRC:         N/A
  13.   SEE-ALSO:     YACC and PREP
  14.   AUTHORS:     Scott Guthery 11100 leafwood lane Austin, TX 78750
  15.   COMPILERS:     DESMET-C
  16.   REFERENCES:     UNIX Systems Manuals
  17. */
  18. /*
  19.  * Copyright (c) 1978 Charles H. Forsyth
  20.  */
  21.  
  22. #include <stdio.h>
  23. #include "lexlex.h"
  24.  
  25. /*
  26.  * Construct the epsilon closure of a given set; this is the set of states
  27.  * that may be reached by some number of epsilon transitions from that state.
  28.  */
  29. struct set *
  30. eclosure(t)
  31. struct set *t;
  32. {
  33.         register struct nfa *np, *xp;
  34.         register i;
  35.         struct nfa **sp, **tp, **ip, *stack[MAXNFA], *temp[MAXNFA];
  36.  
  37.         tp = temp;
  38.         for (sp = stack, i = 0; i < t->s_len; i++)
  39.                 if (sp <= stack+MAXNFA)
  40.                         *tp++ = *sp++ = t->s_els[i];
  41.                 else {
  42.                         error("Stack overflow in `eclosure'");
  43.                         exit(1);
  44.                 }
  45.         while (sp > stack) {
  46.                 np = *--sp;
  47.                 if (np->n_char==EPSILON)
  48.                 for (i = 0; i < 2; i++)
  49.                         if (xp = np->n_succ[i]) {
  50.                                 for (ip = temp; ip < tp;)
  51.                                         if (*ip++ == xp)
  52.                                                 goto cont;
  53.                                 if (tp >= temp+MAXNFA) {
  54.                                         error("eclosure: list overflow");
  55.                                         exit(1);
  56.                                 }
  57.                                 *sp++ = *tp++ = xp;
  58.                         cont:;
  59.                         }
  60.         }
  61.         t = newset(temp, tp-temp, 1);
  62.         return(t);
  63. }
  64.  
  65.